﻿using System;

namespace U01_boke
{
    /// <summary>
    /// 操作结果
    /// </summary>
    public class OperationResult
    {
        public OperationResult(object data)
        {
            this.data = data;
        }
        public OperationResult(string message)
        {
            this.message = message;
        }
        public OperationResult(int status)
        {
            this.status = status;
        }
        public OperationResult(object data, string message)
        {
            this.data = data;
            this.message = message;
        }
        public OperationResult(object data, int status)
        {
            this.data = data;
            this.status = status;
        }
        public OperationResult(string message, int status)
        {
            this.message = message;
            this.status = status;
        }
        public OperationResult(object data, int status, string message)
        {
            this.data = data;
            this.status = status;
            this.message = message;
        }

        public int status { get; set; } = 200;
        public string message { get; set; } = "SUCCESS";
        public object data { get; set; }
    }

    public class PagedingResult : OperationResult
    {
        /// <summary>
        /// 每页数量
        /// </summary>
        public int pageSize { get; set; } = 10;
        /// <summary>
        /// 当前页
        /// </summary>
        public int pageIndex { get; set; } = 1;

        /// <summary>
        /// 总记录数
        /// </summary>
        public int pageTotal { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int pageCount
        {
            get
            {
                return (int)Math.Ceiling(((decimal)pageTotal / pageSize));
            }
        }
        /// <summary>
        /// 下一页
        /// </summary>
        public int next
        {
            get
            {
                return pageIndex == pageCount ? pageCount : pageIndex + 1;
            }
        }
        /// <summary>
        /// 上一页
        /// </summary>
        public int previous
        {
            get
            {
                return pageIndex == 1 ? 1 : pageIndex - 1;
            }
        }

        public PagedingResult(object data) : base(data) { }
        public PagedingResult(object data, int pageIndex) : base(data)
        {
            this.pageIndex = pageIndex;
        }
        public PagedingResult(object data, int pageIndex, int pageTotal) : base(data)
        {
            this.pageIndex = pageIndex;
            this.pageTotal = pageTotal;
        }
        public PagedingResult(object data, int pageIndex, int pageTotal, int pageSize) : base(data)
        {
            this.pageIndex = pageIndex;
            this.pageTotal = pageTotal;
            this.pageSize = pageSize;
        }

        public static PagedingResult Parse(object data, int pageTotal, int pageIndex = 1)
        {
            return new PagedingResult(data)
            {
                pageIndex = pageIndex,
                pageTotal = pageTotal
            };
        }
        public static PagedingResult Parse(object data, int pageTotal, int pageIndex = 1, int pageSize = 10)
        {
            return new PagedingResult(data)
            {
                pageIndex = pageIndex,
                pageTotal = pageTotal,
                pageSize = pageSize
            };
        }
    }
}